﻿/*****************************************************
 * 
 *      creat by ternence
 * 
 *      time 2016-04-05
 *      
 *      describe 带图标的按钮，有点击效果
 * 
 * ***************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NF_Tools
{
    public partial class BF_Lable : Label
    {
        public BF_Lable()
        {
            InitializeComponent();
            this.ImageAlign = ContentAlignment.MiddleLeft;
            this.TextAlign = ContentAlignment.MiddleRight;
            this.Font = new Font(@"微软雅黑", 12);
        }

        public BF_Lable(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        [Category("Ternence"), DisplayName("默认图标")]
        public Image Ternence_ICO { get; set; }

        [Category("Ternence"), DisplayName("鼠标移上图标")]
        public Image Ternence_Hover_ICO { get; set; }

        [Category("Ternence"), DisplayName("得到焦点颜色")]
        public Color HoverColor { get; set; }

        [Category("Ternence"), DisplayName("失去焦点颜色")]
        public Color LeaveColor { get; set; }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                if(!value.Contains(" "))
                    base.Text = "    " + value;
                else
                    base.Text = value;
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            this.Location = new Point(this.Location.X + 1, this.Location.Y + 1);
            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            this.Location = new Point(this.Location.X - 1, this.Location.Y - 1);
            base.OnMouseUp(e);
        }

        protected override void OnMouseHover(EventArgs e)
        {
            this.Image = Ternence_Hover_ICO;
            this.ForeColor = HoverColor;
            base.OnMouseHover(e);
        }


        protected override void OnMouseLeave(EventArgs e)
        {
            this.Image = Ternence_ICO;
            this.ForeColor = LeaveColor;
            base.OnMouseLeave(e);
        }


    }
}
